/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SubsistemaFinanzas;

import clienteSandraParada.Login;
import com.itextpdf.text.Document;
import com.itextpdf.text.Font;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import java.awt.Color;
import java.awt.Desktop;
import java.io.File;
import java.io.FileOutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;

/**
 *
 * @author hernan
 */
public class DialogoInfoPagoEfectivo extends javax.swing.JDialog {

    private PagoEfectivo pago;
    private Long idPago;

    public DialogoInfoPagoEfectivo(java.awt.Frame parent, boolean modal, PagoEfectivo pago, Long id) {
        super(parent, modal);
        initComponents();
        setIconImage(new ImageIcon(getClass().getResource("/GUI/Img/logo2.png")).getImage());
        this.pago = pago;
        this.idPago = id;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel6 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        campoNombreProfesional = new javax.swing.JTextField();
        campoRutProfesional = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        campoRutPaciente = new javax.swing.JTextField();
        campoNombrePaciente = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        campoNumeroBoleta = new javax.swing.JTextField();
        campoValorTotal = new javax.swing.JTextField();
        campoFecha = new javax.swing.JTextField();
        campoHora = new javax.swing.JTextField();
        spinnerNroSesiones = new javax.swing.JSpinner();
        jLabel4 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        botonGuardar = new javax.swing.JButton();
        botonCancelar = new javax.swing.JButton();
        etiquetaMensajeria = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos profesional"));

        jLabel9.setText("Rut:");

        jLabel10.setText("Nombre:");

        campoNombreProfesional.setEnabled(false);

        campoRutProfesional.setEnabled(false);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoRutProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(campoNombreProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(campoRutProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoNombreProfesional, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos paciente"));

        jLabel1.setText("Rut:");

        campoRutPaciente.setEnabled(false);

        campoNombrePaciente.setEnabled(false);

        jLabel6.setText("Nombre:");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(campoRutPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(campoNombrePaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoRutPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoNombrePaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addContainerGap(17, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos pago efectivo"));

        campoValorTotal.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        campoValorTotal.setEnabled(false);

        campoFecha.setEnabled(false);

        campoHora.setEnabled(false);

        spinnerNroSesiones.setModel(new javax.swing.SpinnerNumberModel(1, 1, 99, 1));

        jLabel4.setText("N° de boleta:");

        jLabel7.setText("Fecha:");

        jLabel14.setText("Hora:");

        jLabel15.setText("N° de sesiones:");

        jLabel16.setText("Valor:");

        jLabel2.setText("*");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 90, Short.MAX_VALUE)
                    .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addComponent(campoFecha, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoValorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(24, 24, 24))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(campoNumeroBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
                        .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(spinnerNroSesiones, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(58, 58, 58))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(campoHora, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {campoFecha, campoHora, campoNumeroBoleta, campoValorTotal});

        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoNumeroBoleta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(spinnerNroSesiones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel15)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(campoValorTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel16))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(campoHora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel14))
                .addContainerGap(22, Short.MAX_VALUE))
        );

        jPanel5Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {campoFecha, campoHora, campoNumeroBoleta, campoValorTotal, spinnerNroSesiones});

        jLabel11.setText("* Campos obligatorios");

        botonGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Aceptar.png"))); // NOI18N
        botonGuardar.setText("Guardar");
        botonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonGuardarActionPerformed(evt);
            }
        });

        botonCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/GUI/Img/Iconos16X16/Cancelar.png"))); // NOI18N
        botonCancelar.setText("Cancelar");
        botonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonCancelarActionPerformed(evt);
            }
        });

        etiquetaMensajeria.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        etiquetaMensajeria.setText("Área de mensajería");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(botonGuardar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonCancelar)
                .addContainerGap())
            .addComponent(etiquetaMensajeria, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel11)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(botonGuardar)
                        .addComponent(botonCancelar)))
                .addGap(18, 18, 18)
                .addComponent(etiquetaMensajeria, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGuardarActionPerformed
        if (camposObligatoriosLlenos()) {
            service.PagoEfectivo spb = (service.PagoEfectivo) cargarPagoEfectivo(idPago);
            if (botonGuardar.getText().equalsIgnoreCase("Guardar")) {
                String valorAnterior = "Número boleta: " + spb.getNumeroBoleta() + "\n" + "Rut profesional: " + spb.getRutProfesional() + "\n" + "Nombre profesional: " + spb.getNombresProfesional()
                        + "\n" + "Rut paciente: " + spb.getRutPaciente() + "\n" + "Nombre paciente: " + spb.getNombresPaciente() + "\n"
                        + "\n" + "Fecha: " + spb.getFecha() + "\n" + "Hora: " + spb.getHora() + "\n" + "Número de sesiones: " + spb.getNumeroSesiones() + "\n" + "Valor: " + spb.getValor();
                spb.setNumeroBoleta(campoNumeroBoleta.getText());
                spb.setNumeroSesiones(spinnerNroSesiones.getValue().toString());
                modificarPagoEfectivo(spb);
                String valorNuevo = "Número boleta: " + spb.getNumeroBoleta() + "\n" + "Rut profesional: " + spb.getRutProfesional() + "\n" + "Nombre profesional: " + spb.getNombresProfesional()
                        + "\n" + "Rut paciente: " + spb.getRutPaciente() + "\n" + "Nombre paciente: " + spb.getNombresPaciente() + "\n"
                        + "\n" + "Fecha: " + spb.getFecha() + "\n" + "Hora: " + spb.getHora() + "\n" + "Número de sesiones: " + spb.getNumeroSesiones() + "\n" + "Valor: " + spb.getValor();
                registrar(Login.getUser(), "Pago con efectivo", "Modificó pago con efectivo", valorAnterior, valorNuevo);
                pago.actualizarTabla();
            } else if (botonGuardar.getText().equalsIgnoreCase("Exportar")) {
                try {
                    this.exportarPDF(spb);
                } catch (Exception ex) {
                    Logger.getLogger(DialogoInfoPagoEfectivo.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            this.dispose();
        } else {
            cambiarEtiquetaMensajeria("Debe llenar los campos obligatorios", Color.red);
        }
    }//GEN-LAST:event_botonGuardarActionPerformed

    private void botonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonCancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_botonCancelarActionPerformed

    public void cambiarEtiquetaMensajeria(String mensaje, Color color) {
        etiquetaMensajeria.setText(mensaje);
        etiquetaMensajeria.setForeground(color);
    }

    public JButton getBotonGuardar() {
        return this.botonGuardar;
    }

    public boolean camposObligatoriosLlenos() {
        if (!campoNumeroBoleta.getText().equals("")) {
            return true;
        }
        return false;
    }

    public void exportarPDF(service.PagoEfectivo spago) throws Exception {
        Font fuenteTitulo = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD);
        Font fuenteTexto = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL);
        JFileChooser jF1 = new javax.swing.JFileChooser();
        String ruta;
        try {
            if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) {
                ruta = jF1.getSelectedFile().getAbsolutePath() + ".pdf";
                PdfPTable tabla = new PdfPTable(2);

                tabla.addCell(new PdfPCell(new Paragraph("Rut profesional", fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph(spago.getRutProfesional(), fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph("Nombre profesional", fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph(spago.getNombresProfesional(), fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph("Rut paciente", fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph(spago.getRutPaciente(), fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph("Nombre paciente", fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph(spago.getNombresPaciente(), fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph("Número de boleta", fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph(spago.getNumeroBoleta(), fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph("Fecha", fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph(spago.getFecha(), fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph("Hora", fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph(spago.getHora(), fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph("Número de sesiones", fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph(spago.getNumeroSesiones(), fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph("Valor", fuenteTexto)));
                tabla.addCell(new PdfPCell(new Paragraph(spago.getValor(), fuenteTexto)));

                Document document = new Document();
                PdfWriter.getInstance(document, new FileOutputStream(ruta));
                document.open();
                document.add(new Paragraph("Información de Pago con efectivo", fuenteTitulo));
                document.add(new Paragraph(" ", fuenteTexto));
                document.add(tabla);
                document.close();
                File f = new File(ruta);
                Desktop.getDesktop().open(f);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void habilitarCampos() {
        campoNumeroBoleta.setEnabled(true);
        spinnerNroSesiones.setEnabled(true);
    }

    public void inhabilitarCampos() {
        campoNumeroBoleta.setEnabled(false);
        spinnerNroSesiones.setEnabled(false);
    }

    public void limpiarCampos() {
        campoRutProfesional.setText("");
        campoNombreProfesional.setText("");
        campoRutPaciente.setText("");
        campoNombrePaciente.setText("");
        campoNumeroBoleta.setText("");
        spinnerNroSesiones.setValue(new Integer(1));
        campoFecha.setText("");
        campoValorTotal.setText("");
        campoHora.setText("");
        normalizarMensajeria();
    }

    public void llenarCampos(service.PagoEfectivo pag) {
        this.limpiarCampos();
        campoRutProfesional.setText(pag.getRutProfesional());
        campoNombreProfesional.setText(pag.getNombresProfesional());
        campoRutPaciente.setText(pag.getRutPaciente());
        campoNombrePaciente.setText(pag.getNombresPaciente());
        campoNumeroBoleta.setText(pag.getNumeroBoleta());
        spinnerNroSesiones.setValue(Integer.parseInt(pag.getNumeroSesiones()));
        campoFecha.setText(pag.getFecha());
        campoValorTotal.setText(pag.getValor());
        campoHora.setText(pag.getHora());
    }

    public void normalizarMensajeria() {
        etiquetaMensajeria.setText("Área de mensajería");
        etiquetaMensajeria.setForeground(Color.black);
    }

    public Date stringToDate(String strFecha) {
        SimpleDateFormat formatoDelTexto = new SimpleDateFormat("dd-MM-yyyy");
        Date fecha = null;
        try {
            fecha = formatoDelTexto.parse(strFecha);
        } catch (ParseException ex) {
            ex.printStackTrace();
        }
        return fecha;
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonCancelar;
    private javax.swing.JButton botonGuardar;
    private javax.swing.JTextField campoFecha;
    private javax.swing.JTextField campoHora;
    private javax.swing.JTextField campoNombrePaciente;
    private javax.swing.JTextField campoNombreProfesional;
    private javax.swing.JTextField campoNumeroBoleta;
    private javax.swing.JTextField campoRutPaciente;
    private javax.swing.JTextField campoRutProfesional;
    private javax.swing.JTextField campoValorTotal;
    private javax.swing.JLabel etiquetaMensajeria;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JSpinner spinnerNroSesiones;
    // End of variables declaration//GEN-END:variables

    private static Object cargarPagoEfectivo(java.lang.Long id) {
        service.PagoWS_Service service = new service.PagoWS_Service();
        service.PagoWS port = service.getPagoWSPort();
        return port.cargarPagoEfectivo(id);
    }

    private static boolean modificarPagoEfectivo(service.PagoEfectivo arg0) {
        service.PagoWS_Service service = new service.PagoWS_Service();
        service.PagoWS port = service.getPagoWSPort();
        return port.modificarPagoEfectivo(arg0);
    }

    private static Long registrar(service.Usuario usuario, java.lang.String modulo, java.lang.String accion, java.lang.String valorAnterior, java.lang.String valorNuevo) {
        service.BitacoraWSService service = new service.BitacoraWSService();
        service.BitacoraWS port = service.getBitacoraWSPort();
        return port.registrar(usuario, modulo, accion, valorAnterior, valorNuevo);
    }

}
